#include "StdAfx.h"
#include ".\mfcwpfframe.h"

CMFCWPFFrame::CMFCWPFFrame(void)
{
	m_pMFCWPFPage = NULL;
}

CMFCWPFFrame::~CMFCWPFFrame(void)
{
	if (m_pMFCWPFPage)
	{
		delete m_pMFCWPFPage;
		m_pMFCWPFPage = NULL;
	}
}

///<summary>
///Get Node Attributes from the xaml file using the path and
///calculate the element's rect and
///parse the page element contained in this element
///</summary>
///<param name='szPath'>
///the path in the xaml file
///</param>
///<param name='pXmlParser'>
///the pointer to the xml parser
///</param>
///<param name='oRect'>
///the region of the element that contains this element
///</param>
void CMFCWPFFrame::Parse(const CString & szPath, CECGXmlParser * pXamlParser, const CRect & oRect)
{
	CMFCWPFRect::Parse(szPath, pXamlParser, oRect);

	CString szFilePath;
	if (m_oAttributes.GetAttribute(_ATTRIBUTESOURCE, szFilePath))
	{
		m_pMFCWPFPage = new CMFCWPFPage(szFilePath, m_oRect);
	}
}

///<summary>
///Draw the element's background in the context of pCDCPlus and
///draw the page element contained in this frame element
///according to the "IsEnabled" attribute
///</summary>
///<param name='pCDCPlus'>
///the pointer to the GDI+ display context
///</param>
///<returns>
///true if the element is enabled; false otherwise
///</returns>
bool CMFCWPFFrame::DrawSelf(CDCPlus * pCDCPlus)
{
	if (CMFCWPFElement::DrawSelf(pCDCPlus))
	{
		m_pMFCWPFPage->DrawSelf(pCDCPlus);
		return true;
	}
	return false;
}

///<summary>
///using the element's rect to calculate the page element is clicked or not
///</summary>
///<param name='nFlags'>
///show if there is other keys pushing down
///</param>
///<param name='oPoint'>
///the pointer 
///</param>
///<returns>
///the pointer to the element
///</returns>
CMFCWPFElement * CMFCWPFFrame::MouseLeftButtonUp(int nFlags, const CPoint & oPoint)
{
	return m_pMFCWPFPage->MouseLeftButtonUp(nFlags, oPoint);
}